package yuekao9.dim;

import yuekao9.util.KafkaUtil;
import yuekao9.util.BrodcastProcess;
import yuekao6.util.MyDeserializationSchemaFunction;
import org.apache.flink.api.common.state.MapStateDescriptor;
import com.alibaba.ververica.cdc.connectors.mysql.MySQLSource;
import org.apache.flink.streaming.api.datastream.BroadcastStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.functions.source.SourceFunction;
import org.apache.flink.streaming.api.datastream.BroadcastConnectedStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import yuekao9.util.BroadcastConnect;
public class ReadKafkaOds {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);
        //从ODS层tms_ods主题筛选维度数据并将其打入对应的HBase维表中。（15分）
        DataStreamSource<String> tmsods = env.addSource(KafkaUtil.kafkaSource("tms_ods"));

        tmsods.print();

        SourceFunction<String> sourceFunction = MySQLSource.<String>builder()
                .hostname("hadoop-single")
                .port(3306)
                .databaseList("yk9_1") // monitor all tables under inventory database
                .username("root")
                .password("root")
                .deserializer(new MyDeserializationSchemaFunction()) // converts SourceRecord to String
                .build();


        DataStreamSource<String> streamSource = env.addSource(sourceFunction) ;


        MapStateDescriptor<String, String> mapStateDescriptor = new MapStateDescriptor<>("test", String.class, String.class);

        BroadcastStream<String> broadcast = streamSource.broadcast(mapStateDescriptor);

        BroadcastConnectedStream<String, String> connect = tmsods.connect(broadcast);

        connect.process(new BrodcastProcess(mapStateDescriptor));

        env.execute();
    }
}
